home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / CGAGRAFA.ASM < prev    next >
Assembly Source File  |  1987-12-29  |  3KB  |  183 lines

  1. ;
  2. ; grafix --- cgagrafa.asm
  3. ;
  4. ; stuff to plot points fast in 8086 assembler (BLEECH!!!)
  5. ;
  6. ; Written 4/87 by Scott Snyder (ssnyder@romeo.caltech.edu or @citromeo.bitnet)
  7. ;
  8. ; Modified 5/29/87 by sss to allow for different memory models
  9. ;
  10.  
  11.     title    cgagrafa
  12.  
  13. include macros.ah
  14.  
  15. sseg
  16. endss
  17.  
  18. g_oddoff equ    02000h
  19. g_linsiz equ    80
  20.  
  21. dseg
  22.  
  23.     ex g_drawbuf,     dword
  24.     ex g_pixbyte,     word
  25.     ex g_bitpix,      word
  26.     ex g_colormask,   byte
  27.     ex g_cmask_tbl,   byte
  28.     ex g_hicolormask, byte
  29.     ex g_xor,         word
  30.     ex g_xcliplo,     word
  31.     ex g_xcliphi,     word
  32.     ex g_ycliplo,     word
  33.     ex g_ycliphi,     word
  34.  
  35. endds
  36.  
  37. cseg _cgagrafa
  38.  
  39. ; plot a point. ax = y; bl = c; cx = x;
  40.  
  41. pBegin    plot
  42.  
  43.     les    si, g_drawbuf        ; get address of buffer
  44.     sar    ax, 1            ; y /= 2
  45.     jnc    p1            ; add in offset if it was odd
  46.     add    si, g_oddoff
  47. p1:    mov    dx, g_linsiz        ; y * g_linsiz
  48.     mul    dx
  49.     add    si, ax            ; add to offset
  50.     mov    ax, cx            ; x to AC (ohhh... what symmetry!)
  51.     mov    dx, 0
  52.     div    g_pixbyte
  53.     add    si, ax            ; add quotient to offset (now complete)
  54.     and    bl, g_colormask        ; get cmask
  55.     mov    bl, g_cmask_tbl[bx]
  56.     mov    cx, g_bitpix        ; only works for bitpix = 0 or 1!
  57.     dec    cx
  58.     shl    dx, cl            ; dx = mask shift count
  59.     mov    cx, dx
  60.     mov    dl, g_hicolormask    ; get mask
  61.     shr    dl, cl            ; shift it
  62.     and    bx, dx            ; bx = cmask & mask
  63.     mov    al, es:[si]        ; get image byte
  64.     cmp    g_xor, 0        ; xor mode?
  65.     jne    p2
  66.     not    dl            ; no - (*ptr & ~mask) | (cmask & mask)
  67.     and    al, dl
  68.     or    al, bl
  69.     jmp    p3
  70. p2:    xor    al, bl            ; yes - *ptr ^ (cmask & mask)
  71. p3:    mov    es:[si], al        ; done!
  72.     ret
  73.  
  74. pEnd    plot
  75.  
  76. ;
  77. ; C interface for point plotter
  78. ;
  79. ; CGA_point(x, y, c)
  80. ;
  81.  
  82. pBegin    CGA_point
  83.     push    bp
  84.     mov    bp, sp
  85.     push    si
  86.     push    di
  87.  
  88.     mov    ax, [bp+argbase+2]
  89.     mov    bx, [bp+argbase+4]
  90.     mov    cx, [bp+argbase]
  91.     call    plot
  92.  
  93.     pop    di
  94.     pop    si
  95.     mov    sp, bp
  96.     pop    bp
  97.     ret
  98.  
  99. pEnd    CGA_point
  100.  
  101. ;
  102. ; write for pixels for circle drawing
  103. ;
  104. ; void CGA_write_pix(x1, y1, x2, y2, c)
  105. ;
  106.  
  107. pBegin    CGA_write_pix
  108.  
  109.     push    bp
  110.     mov    bp, sp
  111.     push    si
  112.     push    di
  113.  
  114.     mov    bx, [bp+argbase+8]    ; bx = c (for plot)
  115.     mov    cx, [bp+argbase]    ; cx = x1
  116.     cmp    cx, g_xcliplo        ; check for clipping
  117.     jb    w2
  118.     cmp    cx, g_xcliphi
  119.     ja    w2
  120.  
  121.     mov    ax, [bp+argbase+2]    ; ax = y1
  122.     cmp    ax, g_ycliplo        ; do clipping
  123.     jb    w1
  124.     cmp    ax, g_ycliphi
  125.     ja    w1
  126.  
  127.     push    bx            ; plot (x1, y1)
  128.     push    cx
  129.     call    plot
  130.     pop    cx
  131.     pop    bx
  132.  
  133. w1:    mov    ax, [bp+argbase+6]    ; ax = y2
  134.     cmp    ax, g_ycliplo
  135.     jb    w2
  136.     cmp    ax, g_ycliphi
  137.     ja    w2
  138.  
  139.     push    bx            ; plot (x1, y2)
  140.     call    plot
  141.     pop    bx
  142.  
  143. w2:    mov    cx, [bp+argbase+4]    ; cx = x2
  144.     cmp    cx, g_xcliplo
  145.     jb    w4
  146.     cmp    cx, g_xcliphi
  147.     ja    w4
  148.  
  149.     mov    ax, [bp+argbase+2]    ; ax = y1
  150.     cmp    ax, g_ycliplo        ; do clipping
  151.     jb    w3
  152.     cmp    ax, g_ycliphi
  153.     ja    w3
  154.  
  155.     push    bx            ; plot (x2, y1)
  156.     push    cx
  157.     call    plot
  158.     pop    cx
  159.     pop    bx
  160.  
  161. w3:    mov    ax, [bp+argbase+6]    ; ax = y2
  162.     cmp    ax, g_ycliplo
  163.     jb    w4
  164.     cmp    ax, g_ycliphi
  165.     ja    w4
  166.  
  167.     call    plot            ; plot (x2, y2)
  168.  
  169. w4:    pop    di
  170.     pop    si
  171.     mov    sp, bp
  172.     pop    bp
  173.     ret
  174.  
  175. pEnd    CGA_write_pix
  176.  
  177.     df_ CGA_point
  178.     df_ CGA_write_pix
  179.  
  180. endcs    _cgagrafa
  181.  
  182. end
  183.